FROM golang:1.16.3 as builder

# 设置容器环境变量
ENV GOPROXY=https://goproxy.cn
ENV GOOS=linux
ENV GOARCH=amd64
ENV CGO_ENABLED=0

COPY . /app

WORKDIR /app

RUN go get -u github.com/fvbock/endless

RUN go build -ldflags="-s -w" -installsuffix cgo -o blog-server

FROM alpine as prod

# 开放端口
EXPOSE 9091

# 创建一个目录
RUN mkdir -p /app/logs /app/files

RUN touch /app/logs/memory_box.log && chmod 755 /app/logs/memory_box.log

RUN ls /app

COPY --from=builder /app/blog-server /app

COPY --from=builder /app/config-prov.yml /app

# 启动
CMD ["/app/blog-server", "--config=/app/config-prov.yml"]